package com.situ.crm.controller;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.situ.crm.common.ServerResponse;
import com.situ.crm.entity.Customer;
import com.situ.crm.entity.Customer;
import com.situ.crm.service.ICustomerService;

@Controller
@RequestMapping(value="/customer")
public class CustomerController {
	@Autowired
	private ICustomerService customerService;
	
	@RequestMapping(value="/getCustomerPage")
	public String getCustomer() {
		return "customer/customer_list";
	}
	
	//分页
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Customer customer) {
		ServerResponse serverResponse = customerService.pageList(page,limit,customer);
		return serverResponse;
	}
	
	//添加页面
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "customer/customer_insert";
	}
	
	//添加功能
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Customer customer) {
		return customerService.insert(customer);
	}
	
	//删除功能
	@RequestMapping(value="/deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return customerService.deleteById(id);
	}
	
	//批量删除
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return customerService.deleteAll(ids);
	}
	
	//修改页面
    @RequestMapping(value="getUpdatePage")
	public String getUpdatePage(Integer id,Model model) {
    	Customer customer = customerService.select(id);
    	model.addAttribute("customer",customer);
		return "customer/customer_update";
	}
    
    //修改
    @RequestMapping(value="/update")
    @ResponseBody
    public ServerResponse update(Customer customer) {
    	System.err.println(customer);
		return customerService.update(customer);
	}
    
    //导出报表
    @RequestMapping(value="/exportExcel")
    public void exportExcel(HttpServletResponse response) {
		customerService.exportExcel(response);
	}
}
